package org.arclib.examples.camera;

import java.io.IOException;

import org.arclib.ArcGame;
import org.arclib.Texture;
import org.arclib.draw.Color;
import org.arclib.draw.Draw;
import org.arclib.math.Point;
import org.arclib.math.Size;
import org.arclib.x.camera.Camera;
import org.lwjgl.input.Keyboard;

public class CamTest extends ArcGame
{

	Camera cam;
	Texture t1, t2;
	Point pos;

	protected CamTest(String argT, Size argS, boolean argFS) throws IOException
	{
		super(argT, argS, argFS);
		// TODO Auto-generated constructor stub

		t1 = loader.getTexture("testbin/penguin.png");
		t2 = loader.getTexture("testbin/penguin.png");

		cam = new Camera(window);
		pos = new Point(100, 100);

		// set position of camera
		cam.setPosition(new Point(0, 0));
		cam.setProjection(0, 480, 0, 640);
	}

	public void process()
	{
		cam.process();
		cam.open();

		float val = 1;
		if (Keyboard.isKeyDown(Keyboard.KEY_LEFT))
		{
			cam.moveLeft(val);
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
		{
			cam.moveRight(val);
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_UP))
		{
			// if we don't specify value, it will default to one
			cam.moveUp(val);
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_DOWN))
		{
			cam.moveDown(val);
		}

		// we can set and get zoom
		// cam.setZoom(cam.getZoom);

		// we can zoom in and out if we want to
		if (Keyboard.isKeyDown(Keyboard.KEY_A))
		{
			cam.zoomIn(.1);
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_Z))
		{
			// can insert value if you want to
			cam.zoomOut(.1);
		}

		draw.pixel(pos, Color.Red);

		draw.circle(new Point(100, 10), 25, 20, Color.Red, false);

		draw.line(Point.Zero, pos, Color.Blue);

		draw.rectangle(new Point(0, 100), new Size(50, 100), Color.Blue, true);

		draw.image(t1, new Point(100, 200), new Size(50, 100), Point.Zero, 0,
				Color.White);

		// draw.imageBottomLeft(t2, pos.add(new Point(200,300)), new
		// Size(100,50), Color.White);

		cam.close();
	}

	/**
	 * @param args
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws IOException,
			InterruptedException
	{
		// TODO Auto-generated method stub
		CamTest t = new CamTest("Cam Test", Size.d640x480, false);
		t.run();
	}

}
